<?php

namespace Futures\Controller;
use Think\Controller;
use Futures\Model\OptionModel;

/**
 *  代理商设置控制器
 */
class AgentSetController extends AgentBaseController {
	//密码修改
	public function pwd_change(){
		if(IS_POST){
			//判断是否填入新密码
			if($_POST['new_pwd']){
				$new_pwd = $_POST['new_pwd'];
			}else{
				$this->error('新密码不能为空');
			}
			//判断是否填入原密码
			if($_POST['before_pwd']){
				$before_pwd = $_POST['before_pwd'];
			}else{
				$this->error('请输入原密码');
			}
			$confirm = $_POST['confirm'];
			$id = $_POST['id'];
			$pwd = M('futures_agent')->where('user_id = '.$id)->field('password')->find();
			//判断原密码是否正确
			if(md5($before_pwd) == $pwd['password']){
				if(md5($new_pwd) == $pwd['password']){//判断新密码是否与原密码一致
					$this->error('不能与原密码一致');
				}else{
					$data['password'] = md5($new_pwd);
					M('futures_agent')->where('user_id = '.$id)->save($data);
					session('AGENT',null);
					$this->success('修改成功');
				}
			}else{
				$this->error('原密码不正确');
			}
		}else{
			$this->display();
		}
	}
}
